package net.jxtz.jxtzos.entity.web;

import lombok.Data;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Data
@Component
public final class R implements Serializable {

    private Integer code;

    private String message;

    private Map<String, Object> data = new HashMap<>();

    public static R ok(){
        R r = new R();
        r.setCode(20000);
        r.setMessage("操作成功");
        return r;
    }

    public static R error(){
        R r = new R();
        r.setCode(50000);
        r.setMessage("操作失败");
        return r;
    }

    public R code(Integer code){
        this.code = code;
        return this;
    }

    public R message(String message){
        this.message = message;
        return this;
    }

    public R data(String key, Object value){
        this.data.put(key,value);
        return this;
    }
}
